/**
 * gegewu业务类
 */
define(
    [ "common", "globalsettings","wizard", "components", "service" ],
    function($, gs, wizard, Component,serv) {
      var gegewu = {};

      var COLOR = {
        RED0 : "#DB0011",
        RED1 : "#DF3F12",
        RED2 : "#DC221F",
        RED3 : "#B2001B",
        RED4 : "#DA0011" // 分割线1
        ,
        RED5 : "#B2001B" // 分割线2
        ,
        SHADOW0 : "#2B3723"
      }

      function RENDER_SUB_PANEL(page, c, vw, height, padding, tab_left,
          tab_width, tab_height, tab_radius, shadow_color, bg_image, sox, soy) {
        // c.fillStyle="red";
        // c.fillRect(0,0,vw,self.height);
        /*
         * var x = $.merge([], arguments); x.shift();
         * console.log(JSON.stringify(x));
         */
        var padding2 = padding * 2;
        c.render(function() {
          // 圆角tab背景
          c.roundRect(padding + tab_left + sox, padding + soy, tab_width,
              tab_height + tab_radius, tab_radius);// 阴影
          c.fillStyle = shadow_color;
          c.fill();
          c.roundRect(padding + tab_left, padding, tab_width, tab_height
              + tab_radius, tab_radius);
          c.clip();
          c.drawImage(bg_image, 0, 0, vw, height);

        });
        c.render(function() {
          // 方形背景
          // console.log(height+","+padding+","+tab_height);
          c.rect(padding + sox, padding + tab_height + soy, vw - padding2,
              height - padding2 - tab_height);
          c.fillStyle = shadow_color;
          c.fill();
          c.rect(padding, padding + tab_height, vw - padding2, height
              - padding2 - tab_height);
          c.clip();
          c.drawImage(bg_image, 0, 0, vw, height);
        });
        // console.log("render sub panel");
      }

      /**
       * 高亮部分面板.
       */
      gegewu.BaseSubPanel = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({}, {
          height : 300,
          padding : 50,
          tabLeft : 120,
          tabWidth : 250,
          tabHeight : 100,
          tabRadius : 10,
          shadowColor : "black",
          shadowOffsetX : 3,
          shadowOffsetY : 5,
          bgImage : imgs["bg1"]
        }, settings);
        self.height = self.settings.height;
      }, "ggwBaseSubPanel");

      gegewu.BaseSubPanel.prototype.setHeight = function(height) {
        // console.log("set height:"+height);
        this.height = height;
        this.settings.height = height;
      }

      defFunction(gegewu.BaseSubPanel, "renderComp", function(page, c, vw, vh) {
        var self = this;
        c.render(function() {
          var s = self.settings;
          // console.log("settings:"+JSON.stringify(s));
          RENDER_SUB_PANEL(page, c, vw, self.height, s.padding, s.tabLeft,
              s.tabWidth, s.tabHeight, s.tabRadius, s.shadowColor, s.bgImage,
              s.shadowOffsetX, s.shadowOffsetY);
        });
      });

      /**
       * 页头和页脚的灯. direct:0-上,1下; order:0-left2right,1-right2left
       */
      gegewu.Lampad = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({}, {
          height : 365,
          direct : 0,
          order : 0
        }, settings);
        self.height = self.settings.height;
        self.colors = [ COLOR.RED0, COLOR.RED1, COLOR.RED2, COLOR.RED3 ];
        self.triangleCount = self.colors.length;
        self.triangleCenterY = self.height;

        self.tm = new Date().getTime();
      }, "Lampad");

      defineFunction.call(gegewu.Lampad.prototype, "renderComp", function(t, c,
          vw, vh) {
        var self = this;
        var tm = new Date().getTime();
        c.render(function() {
          var triangle_width = vw / self.triangleCount;
          var triangle_offset_x = 0;
          var half_vw = vw / 2;
          var i = 0;
          for (i = 0; i < self.triangleCount; i++) {
            c.beginPath();
            c.moveTo(i * triangle_width, self.settings.drict == 1 ? 0
                : self.height);
            c.lineTo((i + 1) * triangle_width, self.settings.drict == 1 ? 0
                : self.height);
            c.lineTo(half_vw, self.settings.drict == 1 ? self.triangleCenterY
                : 0);
            c.closePath();
            // console.log(tm-self.tm);
            var idx = Math.abs(self.triangleCount + i
                + (self.settings.order == 0 ? -1 : 1)
                * Math.floor((tm - self.tm) / 1000))
                % self.triangleCount;
            c.fillStyle = self.colors[idx];
            c.strokeStyle = self.colors[idx];
            c.fill();
            c.stroke();
          }
        });

      });

      // 格格巫的页面头
      gegewu.Header = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({}, {
          height : 500
        }, self.settings, settings);
        self.height = self.settings.height;
        self.colors = [ COLOR.RED0, COLOR.RED1, COLOR.RED2, COLOR.RED3 ];
        // self.colorOffset=0;
        self.ggwImgSize = self.height * .55;
        self.ggwImgOffsetY = (self.height - self.ggwImgSize) * .9;
        self.triangleCount = self.colors.length;
        self.triangleCenterY = self.ggwImgOffsetY + self.ggwImgSize * .6;
        self.txtAzCatOffsetY = -self.ggwImgSize * .25;
        self.txtAzCatOffsetX = -self.ggwImgSize * .6;
        self.txtAzCatWidth = self.ggwImgSize * 1.2;
        self.txtAzCatHeight = self.ggwImgSize * .8;
        self.txtGargamelOffsetY = self.ggwImgOffsetY / 3;
        self.txtGargamelHeight = (self.height - self.ggwImgSize) * .8;
        self.sepBarHeight = (self.height - self.ggwImgSize) * .1;
        self.sepBarOffsetY = self.height - self.sepBarHeight;
        self.tm = new Date().getTime();

      }, "ggwHeader");

      gegewu.Header.prototype.status = 0;
      defineFunction.call(gegewu.Header.prototype, "renderComp", function(t, c,
          vw, vh) {
        var self = this;
        var tm = new Date().getTime();
        c.render(function() {

          // c.fillStyle="white";
          // c.fillRect(0,0,vw,self.height);

          var triangle_width = vw / self.triangleCount;
          var triangle_offset_x = 0;
          var half_vw = vw / 2;
          var i = 0;
          for (i = 0; i < self.triangleCount; i++) {
            c.beginPath();
            c.moveTo(i * triangle_width, 0);
            c.lineTo((i + 1) * triangle_width, 0);
            c.lineTo(half_vw, self.triangleCenterY);
            c.closePath();
            // console.log(tm-self.tm);
            var idx = Math.abs(self.triangleCount + i
                - Math.floor((tm - self.tm) / 1000))
                % self.triangleCount;
            c.fillStyle = self.colors[idx];
            c.strokeStyle = self.colors[idx];
            c.fill();
            c.stroke();
          }

          // self.colorOffset=(self.colorOffset+1)%self.triangleCount;

          // 绘制格格巫头像
          var imgGgw = imgs.gegewu;
          if (imgGgw.loaded) {
            c.render(function() {
              var w = self.ggwImgSize;
              var h = w;
              c.t((vw - w) / 2, self.ggwImgOffsetY);
              c.drawImageIn(imgGgw, 0, 0, w, h);
            });
          }

          // 绘制gargamel文字
          var imgTxtGargamel = imgs.txtGargamel;
          if (imgTxtGargamel.loaded) {
            c.render(function() {
              c.t(half_vw, self.txtGargamelOffsetY);
              c.drawImageIn(imgTxtGargamel, -vw * .4, 0, vw * .8,
                  self.txtGargamelHeight);
            });
          }

          // 绘制azizcat的文字
          var imgTxtAzCat = imgs.txtAzCat;
          if (imgTxtAzCat.loaded) {
            c.render(function() {
              c.t(half_vw, self.ggwImgOffsetY);
              c
                  .drawImageIn(imgTxtAzCat, self.txtAzCatOffsetX,
                      self.txtAzCatOffsetY, self.txtAzCatWidth,
                      self.txtAzCatHeight);
            });
          }

          // 绘制分割线
          c.render(function() {
            c.beginPath();
            c.rect(0, self.sepBarOffsetY, vw, self.sepBarHeight);
            c.closePath();
            // c.fillStyle="blue";
            // c.fill();
            c.clip();
            // self.sepBarHeight=(self.height-self.ggwImgSize)*.05;
            // self.sepBarOffsetY=self.height-self.sepBarHeight;
            c.t(((tm - self.tm) / 2) % (vw * 2), 0);
            c.t(0, self.sepBarOffsetY);
            c.fillStyle = COLOR.RED4;
            c.beginPath();
            c.moveTo(0, 0);
            c.lineTo(vw, 0);
            c.lineTo(vw, self.sepBarHeight);
            c.closePath();
            c.fill();
            c.stroke();
            c.fillStyle = COLOR.RED5;
            c.beginPath();
            c.moveTo(0, 0);
            c.lineTo(vw, self.sepBarHeight);
            c.lineTo(0, self.sepBarHeight);
            c.closePath();
            c.fill();
            c.stroke();

            c.t(-vw, 0);
            c.fillStyle = COLOR.RED5;
            c.beginPath();
            c.moveTo(0, 0);
            c.lineTo(vw, 0);
            c.lineTo(vw, self.sepBarHeight);
            c.closePath();
            c.fill();
            c.stroke();
            c.fillStyle = COLOR.RED4;
            c.beginPath();
            c.moveTo(0, 0);
            c.lineTo(vw, self.sepBarHeight);
            c.lineTo(0, self.sepBarHeight);
            c.closePath();
            c.fill();
            c.stroke();

            c.t(-vw, 0);
            c.fillStyle = COLOR.RED4;
            c.beginPath();
            c.moveTo(0, 0);
            c.lineTo(vw, 0);
            c.lineTo(vw, self.sepBarHeight);
            c.closePath();
            c.fill();
            c.stroke();
            c.fillStyle = COLOR.RED5;
            c.beginPath();
            c.moveTo(0, 0);
            c.lineTo(vw, self.sepBarHeight);
            c.lineTo(0, self.sepBarHeight);
            c.closePath();
            c.fill();
            c.stroke();
          });

        });
      });

      gegewu.Banner = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({}, {
          height : 550,
          padding : 50,
          imgs : [ "banner0" ]
        }, self.settings, settings);
        self.height = self.settings.height;
        self.padding = self.settings.padding;
        self.padding2 = self.settings.padding * 2;
      }, "ggwBanner");

      gegewu.Banner.prototype.status = 0;
      defineFunction.call(gegewu.Banner.prototype, "renderComp", function(t, c,
          vw, vh) {
        var self = this;
        c.render(function() {
          c.t(self.padding, 0);
          var l = 0, t = 0, w = vw - self.padding2, h = self.height
              - self.padding / 2;
          c.render(function() {
            c.t(3, 5);
            c.fillStyle = COLOR.SHADOW0;
            c.fillRect(l, t, w, h)
          });
          c.drawImage(imgs[self.settings.imgs[0]], l, t, w, h);
        });
      });

      /**
       * 格格巫操作面板类.
       */
      gegewu.OpPanel = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({}, {
          height : 120,
          padding : 100,
          buttonHeight : 80,
          buttonColor : COLOR.RED4,
          buttonTextColor : "white",
          buttons : []
        }, self.settings, settings);
        self.height = self.settings.height;
        self.padding = self.settings.padding;
        self.buttonHeight = self.settings.buttonHeight;
        self.buttons = self.settings.buttons;
        self.buttonColor = self.settings.buttonColor;
        self.buttonTextColor = self.settings.buttonTextColor;
        self.buttonIconSize = self.settings.buttonHeight * .5;
        self.tm = new Date().getTime();
      }, "ggwOpPanel");

      gegewu.OpPanel.prototype.status = 0;
      defineFunction.call(gegewu.OpPanel.prototype, "renderComp", function(t,
          c, vw, vh) {
        var self = this;
        var tm_idx = ((new Date().getTime() - self.tm) / 1000) % 8;
        // console.log(tm_idx);
        c.render(function() {
          var btns_count = self.buttons.length;
          var btn_pnl_wid = (vw - self.padding * 2) / btns_count;
          var btn_btn_wid = btn_pnl_wid - 20;
          c.t(self.padding, 0);
          var tw = 0;
          var icon_tw = 0;
          $(self.buttons).each(
              function(i) {
                var button = this;
                c
                    .render(function() {
                      c.t(i * btn_pnl_wid + btn_pnl_wid / 2,
                          self.buttonHeight / 2);

                      c.render(function() {
                        c.fillStyle = COLOR.SHADOW0;
                        var sd = 8;
                        c.t(tm_idx < 4 ? (-sd + tm_idx / 4 * sd * 2)
                            : (sd - (tm_idx - 4) / 4 * sd * 2),
                            tm_idx < 2 ? (-tm_idx / 2 * sd)
                                : (tm_idx < 6 ? -(sd - (tm_idx - 2) / 2 * sd)
                                    : -(-sd + (tm_idx - 6) / 2 * sd)));
                        c.roundRect(-btn_btn_wid / 2, -self.buttonHeight / 2,
                            btn_btn_wid, self.buttonHeight, 10);
                        c.fill();
                      });

                      c.fillStyle = self.buttonColor;
                      c.roundRect(-btn_btn_wid / 2, -self.buttonHeight / 2,
                          btn_btn_wid, self.buttonHeight, 10);
                      c.fill();

                      t.whenClick(-btn_btn_wid / 2, -self.buttonHeight / 2,
                          btn_btn_wid, self.buttonHeight, function() {
                            button.onClick.call(button);
                          });
                      var txt = button.label;
                      if ($.isFunction(txt)) {
                        txt = txt();
                      }
                      c.font = FONT.pingfangR(self.buttonIconSize);
                      tw = c.measureText(txt).width;
                      icon_tw = tw + self.buttonIconSize * 1.5;
                      c.fillStyle = self.buttonTextColor;
                      c.fillText(txt, -icon_tw / 2 + self.buttonIconSize * 1.5,
                          0);
                      c.drawImage(imgs[button.icon], -icon_tw / 2,
                          -self.buttonIconSize / 2, self.buttonIconSize,
                          self.buttonIconSize);
                    });
              });
        });
      });

      /**
       * 商品子面板.
       */
      gegewu.GoodsSubPanel = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({}, {
          goods : [],
          backgoundImage : "bg1",
          fontSize : 48,
          color : "white"
        }, settings);
        console.log("                 "+self.settings.goods);
        self.goods = (self.settings.goods ? self.settings.goods : []);
        self.height = self.settings.height;
        self.goods = [];

        self.basePanel = new gegewu.BaseSubPanel({
          height : self.height,
          padding : self.padding,
          tabLeft : self.tabLeft,
          tabWidth : self.tabWidth,
          tabHeight : self.tabHeight,
          tabRadius : self.tabRadius,
          shadowColor : self.shadowColor,
          shadowOffsetX : self.shadowOffsetX,
          shadowOffsetY : self.shadowOffsetY,
          bgImage : imgs["bg1"]
        });
      }, "GoodsSubPanel");

      gegewu.GoodsSubPanel.prototype.status = 0;
      gegewu.GoodsSubPanel.prototype.tabLeft = 120;
      gegewu.GoodsSubPanel.prototype.tabWidth = 250;
      gegewu.GoodsSubPanel.prototype.tabHeight = 100;
      gegewu.GoodsSubPanel.prototype.tabRadius = 10;
      gegewu.GoodsSubPanel.prototype.padding = 50;
      gegewu.GoodsSubPanel.prototype.shadowColor = "black";
      gegewu.GoodsSubPanel.prototype.shadowOffsetX = 3;
      gegewu.GoodsSubPanel.prototype.shadowOffsetY = 5;

      gegewu.GoodsSubPanel.prototype.headerHeight = 80;
      gegewu.GoodsSubPanel.prototype.footerHeight = 80;
      gegewu.GoodsSubPanel.prototype.footerPadding = 20;
      gegewu.GoodsSubPanel.prototype.footerPadding2 = gegewu.GoodsSubPanel.prototype.footerPadding * 2;
      gegewu.GoodsSubPanel.prototype.goods = [];
      gegewu.GoodsSubPanel.prototype.basePanel = undefined;

      defineFunction.call(gegewu.GoodsSubPanel.prototype, "addGoods", function(
          goods) {
        var self = this;
        goods && self.goods.push(goods);
      });

      defineFunction.call(gegewu.GoodsSubPanel.prototype,
          "renderPanelBackground", function(t, c, vw) {
            var self = this;
            /*
             * var shadow_color=COLOR.SHADOW0; var padding = self.padding; var
             * tab_left = self.tabLeft; var tab_width = self.tabWidth; var
             * tab_height = self.tabHeight; var tab_radius = self.tabRadius; var
             * height = self.height; var bg_image =
             * imgs[self.settings.backgroundImage];
             * 
             * RENDER_SUB_PANEL(page,c,vw,height,padding,tab_left,tab_width,tab_height,tab_radius,shadow_color,bg_image);
             */
            // console.log("apply");
            // console.log(self.basePanel.height);
            self.basePanel// &&(function(height){self.basePanel.height=height;return
                // true;})(700)
                && self.basePanel.renderComp
                && self.basePanel.renderComp.apply(self.basePanel, arguments);
          });

      /**
       * 子面板下面的文字
       */
      defineFunction.call(gegewu.GoodsSubPanel.prototype, "renderPanelFooter",
          function(t, c, vw) {
            var self = this;
            c.render(function() {
              // c.t(vw/2,self.height-self.padding-self.footerHeight*1.5);
              c.t(0, self.height - self.padding - self.footerHeight);
              var imgFoot = imgs.txtGgwAndAzc;
              // var imgw=imgFoot.width/imgFoot.height*self.footerHeight;
              c.drawImageIn(imgFoot, 0, self.footerPadding, vw,
                  self.footerHeight - self.footerPadding2);
            });
          });

      gegewu.GoodsSubPanel.prototype.calcWordWidth = function(c, txt) {
        var res = 0;
        for (var i = 0; i < txt.length; i++) {
          res = Math.max(res, c.measureText(txt[i]).width);
        }
        return res;
      }

      gegewu.GoodsSubPanel.prototype.renderGoodsName = function(c, txt, ww) {
        var self = this;
        var fs = self.settings.fontSize;
        if (txt.length > 4) {
          // fs=fs/2;
        }
        c.fillStyle = self.settings.color;
        /*
         * c.shadowColor = "rgba(0,0,0,1)"; c.shadowBlur = 5; c.shadowOffsetX =
         * 3; c.shadowOffsetY = 5;
         */
        c.font = FONT.miaowu(fs);
        c.t(0, fs / 2);
        c.t(ww * (1 - Math.ceil(txt.length / 4)), 0);
        c.render(function() {
          for (var i = 0; i < txt.length; i++) {
            if (i > 0 && i % 4 == 0) {
              c.t(ww, -4 * fs);
            }
            c.fillText(txt[i], 0, 0);
            c.t(0, fs);
          }
        });
      }

      /**
       * .
       */
      defineFunction
          .call(
              gegewu.GoodsSubPanel.prototype,
              "renderRenderGoods",
              function(t, c, vw) {
                var self = this;
                
                var goods_width = vw / self.goods.length;
                var offsetY = self.padding + self.tabHeight + self.headerHeight;
                var goods_height = (self.height - offsetY - self.footerHeight - self.padding);
                console.log(JSON.stringify(self.goods));
                c.render(function() {
                  c.t(0, offsetY);
                  $(self.goods).each(
                      function(i) {
                        var goods = this;
                        c.render(function() {
                          c.t(i * goods_width, 0);
                          var img = serv.loadServImg(goods.photo0);//imgs[goods.smallImage];
                          if (!img.loaded) {
                            return;
                          }
                          
                          c.shadowColor = "rgba(0,0,0,1)";
                          c.shadowBlur = 5;
                          c.shadowOffsetX = 3;
                          c.shadowOffsetY = 5;
                          c.drawImageIn(img, 0, 0, goods_width, goods_height);
                          t.whenClick(0, 0, goods_width, goods_height,
                              function() {
                                goods.onClick && $.isFunction(goods.onClick)
                                    && goods.onClick();
                              });
							
                          // 渲染产品名称
                          c.render(function() {
                            var w = img.width / img.height * goods_height;
                            var p = (goods_width - w) / 2;
                            c.font = FONT.miaowu(self.settings.fontSize);

                            var ww = self.calcWordWidth(c, goods.name);
                            switch (i) {
                            case 0:
                              c.t(w + p, 0);
                              break;
                            case 1:
                            default:
                              c.t(p - ww, goods_height
                                  - (goods.name.length > 4 ? 4
                                      : goods.name.length)
                                  * self.settings.fontSize);
                              break;
                            }
                            self.renderGoodsName(c, goods.name, ww);

                          });
                          /*
                           * // 渲染产品价格 c.render(function() { var w = img.width /
                           * img.height * goods_height; var p = (goods_width -
                           * w) / 2; c.font =
                           * FONT.miaowu(self.settings.fontSize); var ww =
                           * self.calcWordWidth(c, goods.price + "元"); switch
                           * (i) { case 0: c.t(w + p, goods_height); break; case
                           * 1: default: c.t(p, 0); break; } c.render(function() {
                           * c.fillStyle = "red"; c.shadowColor = "black";
                           * c.shadowBlur = 5; c.shadowOffsetX = 3;
                           * c.shadowOffsetY = 5; var txt = goods.price + "元";
                           * var tw = c.measureText(txt).width; c.font = FONT
                           * .miaowu(self.settings.fontSize * 1.25); c.t(-tw / 2 +
                           * (i % 2 == 0 ? 0 : w) + self.settings.fontSize * .1,
                           * 0); c.rotate((i % 2 == 0 ? -1 : 1) * Math.PI *
                           * 0.25);// 0.3时会有一个多余的线 c.beginPath(); c.rect(0,
                           * -self.settings.fontSize * 1.25 / 2, tw,
                           * self.settings.fontSize * 1.25); c.closePath(); //
                           * c.clip(); c.fillText(txt, 0, 0); }); //
                           * self.renderGoodsName(c,goods.price+"元",ww);
                           * 
                           * });
                           */

                        });
                      });
                });
                // console.log("a")
              });

      defineFunction.call(gegewu.GoodsSubPanel.prototype, "renderComp",
          function(t, c, vw, vh) {
            var self = this;
            try {
              self.renderPanelBackground(t, c, vw);
              self.renderRenderGoods(t, c, vw);
              self.renderPanelFooter(t, c, vw);
            } catch (e) {
              console.log(e);
            }
          });

      /**
       * 商品详细
       */
      gegewu.GoodsDetailPanel = defClass(Panel, function(settings) {
        this.settings = $.extend({}, settings);
        $.extend(this, this.settings);
      }, "ggwGoodsDetailPanel");

      /*
       * 设置要显示的商品.
       */
      gegewu.GoodsDetailPanel.prototype.setGoods = function(goods) {
        this.__pregoods = this.goods;
        this.goods = goods;
      }

      /*
       * 组合面板
       */
      gegewu.GoodsDetailPanel.prototype.compose = function(page, c, vw, vh, bw,
          bh) {
        // console.log("goods0:"+JSON.stringify(this.goods) );
        if ((!this.goods) || (this.goods == this.__pregoods)) {
          return;
        }
        var goods = this.goods;
        this.clear();
        // console.log("goods:"+JSON.stringify(this.goods));
        this.addComp(new ImageButton({
          image : goods.smallImage,
          left : 20,
          top : 20,
          width : 1040,
          height : 1350
        // 1350=1040/300*450

        }));
        this.addComp(new ImageButton({
          image : "d" + goods.smallImage,
          left : 20,
          top : 0,
          width : 1040,
          height : 518
        // 518=1040/386*250

        }));
        this.addComp(new EmptyPanel({
          height : 20
        }));
        this.addComp(new TextButton({
          text : "添加到购物车",
          left : 540,
          top : 30,
          fontSize : 48,
          font : FONT.pingfangR,
          color : "white",
          bgColor : "red",
          isCenter : true,
          padding : 5,
          radius : 5,
          onClick : function() {
            // console.log("goods:"+JSON.stringify(goods))
            serv.addCommodities2ShoppingCart(page, goods.id, 1, 1);
          }
        }));
        this.__pregoods = this.goods;
      }
      // 渲染订单
      function ggwGoodsDetailPanel_renderComp(page, c, vw, vh, bw, bh) {
        this.compose(page, c, vw, vh, bw, bh);
        this["renderComp::Panel"].apply(this, arguments);
        this.height = this.contentHeight;
      }

      defFunc(gegewu.GoodsDetailPanel, "renderComp",
          ggwGoodsDetailPanel_renderComp);

      /**
       * 显示商品的面板
       */
      gegewu.GoodsPanel = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({}, {
          goods : [ {}, {} ],
          backgoundImage : "bg1"
        }, self.settings, settings);
        
        self.setGoods(self.settings.goods);
      }, "ggwGoodsPanel");

      gegewu.GoodsPanel.prototype.status = 0;
      /**
       * 子面板高度
       */
      gegewu.GoodsPanel.prototype.singleHeight = 700;
      /**
       * 子面板数量.
       */
      gegewu.GoodsPanel.prototype.subPanelsCount = 0;

      defineFunction.call(gegewu.GoodsPanel.prototype, "setGoods", function(
          goods) {
        var self = this;
        self.goods = [];
        $.merge(self.goods, goods);
        self.settings.goods = self.goods;
        self.subPanelsCount = Math.ceil(goods.length / 2);
        self.height = self.subPanelsCount * self.singleHeight;
        self.goodsGroup = [];
        for (var i = 0; i < self.subPanelsCount; i++) {
          self.goodsGroup.push(new gegewu.GoodsSubPanel({
            height : self.singleHeight,
            backgoundImage : self.settings.GoodsSubPanel
          }));
        }
        $(self.goods).each(function(i) {
          // console.log(i+","+Math.floor(i/2))
          self.goodsGroup[Math.floor(i / 2)].addGoods(this);
        });
      });

      defineFunction.call(gegewu.GoodsPanel.prototype, "renderComp", function(
          t, c, vw, vh) {
        var self = this;
        var args = arguments;
        c.render(function() {
          $(self.goodsGroup).each(function() {
            this.renderComp.apply(this, args);
            c.t(0, this.height);
          });
        });

      });

      gegewu.Footer = defClass(GroupComponent, function(settings) {
        var self = this;
        self.settings = $.extend({}, {}, self.settings, settings);
        self.comps.push(new gegewu.Lampad({
          top : 0,
          height : 367.5
        }));
        self.comps.push(new ImageButton({
          image : "azcat",
          top : -100,
          left : 420,
          height : 275,
          width : 240
        }));
        // self.comps.push(new ImageButton({image:""}));

      }, "ggwFooter");

      defineFunction.call(gegewu.Footer.prototype, "renderComp", function(t, c,
          vw, vh) {
        var self = this;
        self["renderComp::GroupComponent"].apply(self, arguments);
      });

      /**
       * 提示
       */
      gegewu.ShadeTip = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({
          backgroundColor : "white",
          backgroundAlpha : "0.7",
          image : "loading",
          text : "正在操作购物车，请稍后",
          isAppendDot : true,
          maxDotCount : 3,
          dot : ".",
          textColor : "white",
          textShadowColor : "black",
          fontSize : 48,
          shadowBlur : 5,
          shadowOffsetX : 3,
          shadowOffsetY : 5,
          direct : 0, // 0-clockwise;1-counter clockwise
          onClick : $.noop
        }, settings);
        self.settings.tm = $.now();

      }, "ggwShadeTip");

      defFunction(gegewu.ShadeTip, "renderComp", function(page, c, vw, vh, bw,
          bh) {
        var self = this;
        var tm = $.now();
        var dd = tm - self.settings.tm;
        var a = dd % 10000 * Math.PI * 2 / 10000;
        c.render(function() {
          c.fillStyle = self.settings.backgroundColor;
          c.globalAlpha = self.settings.backgroundAlpha;
          c.fillRect(0, 0, vw, vh);
          page.whenClick(0, 0, vw, vh, function() {
            var fn = self.settings.onClick;
            var res = undefined;
            if (fn && $.isFunction(fn)) {
              res = self.settings.onClick();
            }
            return res;
          });
        });
        var w = 0;
        var h = 0;
        c.render(function() {
          var img = window.imgs[self.settings.image];
          if (img && img.loaded) {
            w = img.width;
            h = img.height;
            c.t(vw / 2, vh / 2);
            c.rotate((self.settings.direct == 0 ? 1 : -1) * a);
            c.drawImage(img, -w / 2, -h / 2);
          }
        });

        var txt = self.settings.text;
        if (self.settings.isAppendDot) {
          var dot_count = Math.floor(dd / 1000) % self.settings.maxDotCount;
          for (var i = 0; i <= dot_count; i++) {
            txt += self.settings.dot;
          }
        }
        c.font = FONT.pingfangR(self.settings.fontSize);
        c.fillStyle = self.settings.textColor;
        c.shadowColor = self.settings.textShadowColor;
        c.shadowBlur = self.settings.shadowBlur;
        c.shadowOffsetX = self.settings.shadowOffsetX;
        c.shadowOffsetY = self.settings.shadowOffsetY;
        c.t(vw / 2, vh / 2 + -h / 2 - self.settings.fontSize);
        var tw = c.measureText(txt).width;
        c.fillText(txt, -tw / 2, self.settings.fontSize / 2);

      });

      /**
       */
      gegewu.CartSubPanel = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({}, settings);
        self.basePanel = new gegewu.BaseSubPanel({});
        self.setHeight(700);
      }, "ggwCartSubPanel");

      defFunc(gegewu.CartSubPanel, "setGoods", function(goods) {
        this.goods = goods;
      });

      defFunc(gegewu.CartSubPanel, "setHeight", function(height) {
        this.height = height;
        var ps = this.basePanel.settings;// panel settings
        var ps_padding2 = ps.padding * 2;
        this.imgOffsetX = ps.padding * 2;
        this.imgOffsetY = ps_padding2 + ps.padding + ps.tabHeight;
        this.imgHeight = this.height - this.imgOffsetY - ps_padding2;
      });

      /**
       * 渲染购物车中的物品.
       */
      defFunc(gegewu.CartSubPanel, "renderComp", function(page, c, vw, vh, bw,
          bh) {
        // console.log("cart sub panel render as comp");
        var self = this;
        var goods = self.goods;
        var ps = this.basePanel.settings;// panel settings
        // console.log(self.basePanel);
        // console.log("self.height:"+self.height);
        // 背景面板
        c.render(function() {
          self.basePanel.setHeight(self.height);
          self.basePanel.render(page, c, vw, vh, bw, bh);
        });
        // console.log(JSON.stringify(self.goods));
        // 图片
        var imgWidth = 0;
        var imgHeight = 0;
        c.render(function() {
          var img = imgs[goods.mainImg];
          // console.log(img);
          // console.log(img.loaded);
          // var offsetX = self.height-self.basePanel.settings.padding;
          // console.log(offsetX);
          if (!img.loaded) {
            return;
          }
          var img_width = img.width;
          var img_height = img.height;

          var height = self.imgHeight;
          var width = img_width * height / img_height;
          // console.log(self.imgOffsetX+","+self.imgOffsetY+","+width+","+height);
          c.drawImage(img, self.imgOffsetX, self.imgOffsetY, width, height);
          imgWidth = width;
          imgHeight = height;
        });

        var nameOffsetX = self.imgOffsetX + imgWidth + ps.padding;
        var nameOffsetY = self.imgOffsetY;
        var nameFs = 48;
        // 渲染商品名称
        c.render(function() {
          var fs = nameFs;
          var fs_h = fs / 2;
          c.font = FONT.miaowu(fs);
          c.fillStyle = "white";
          c.t(nameOffsetX, nameOffsetY + fs_h);
          c.fillText(goods.commodityName, 0, 00);
        });

        var priceOffsetX = nameOffsetX;
        var priceOffsetY = nameOffsetY + ps.padding * 2;
        var priceFs = 48;

        var priceBgWidth = 0;
        // 渲染价格
        c.render(function() {
          var img = imgs.priceBg;
          if ((!img) || !img.loaded) {
            return;
          }
          c.t(priceOffsetX, priceOffsetY);
          // console.log(imgs.priceBg);
          c.drawImage(img, 0, 0);
          var width = img.width;
          var height = img.height;
          c.t(width / 2, height / 2);
          var txt = $.numberUtils("format", self.goods.price / 100, "0.99")
              + "元";
          c.font = FONT.miaowu(priceFs);
          c.fillStyle = "red";
          var tw = c.measureText(txt).width;
          c.fillText(txt, -tw / 2, 0);
          priceBgWidth = width;
        });

        var opOffsetX = priceOffsetX + priceBgWidth + ps.padding;
        var opOffsetY = priceOffsetY + ps.padding / 2;
        var opFs = 48;
        var opHeight = opFs + 10;
        var opWidth = 0;
        c.render(function() {
          c.t(opOffsetX, opOffsetY);
          c.strokeStyle = "white";
          c.lineWidth = 1;
          c.font = FONT.pingfangR(opFs);
          var tw = c.measureText(goods.amount).width;
          var txt_width = tw + 10;
          txt_width = (txt_width < opHeight * 2 ? opHeight * 2 : txt_width);
          opWidth = opHeight * 2 + txt_width;
          c.strokeRect(0, 0, opHeight, opHeight);
          page.whenClick(0, 0, opHeight, opHeight, function() {
            $(page).trigger({
              type : "minusCartGoods",
              goods : goods
            });
            return false;
          });
          c.strokeRect(opHeight, 0, txt_width, opHeight);
          c.strokeRect(opHeight + txt_width, 0, opHeight, opHeight);
          page.whenClick(opHeight + txt_width, 0, opHeight, opHeight,
              function() {
                $(page).trigger({
                  type : "addCartGoods",
                  goods : goods
                });
              });
          // - 号
          c.render(function() {
            c.t(opHeight / 4, opHeight / 2);
            c.strokeStyle = "white";
            c.strokeLine(opHeight / 2, 0);

          });
          // +号
          c.render(function() {
            c.stokeStyle = "white";
            c.t(opHeight * 1.25 + txt_width, opHeight / 2);
            c.strokeLine(opHeight / 2, 0);
            c.t(opHeight / 4, -opHeight / 4);
            c.strokeLine(0, opHeight / 2);
          });
          // 数量
          c.render(function() {
            c.fillStyle = "red";
            c.t(opHeight + txt_width / 2, opHeight / 2);
            c.fillText(goods.amount, -tw / 2, 0);
          });
        });

        var delOffsetX = opOffsetX;
        var delOffsetY = opOffsetY + opHeight + ps.padding;
        var delFs = 36;
        var delHeight = delFs + 20;
        var delWidth = 0;
        c.render(function() {
          c.t(delOffsetX, delOffsetY);
          c.fillStyle = "red";
          c.shadowColor = "black";
          c.shadowOffsetX = 3;
          c.shadowOffsetY = 5;
          c.shadowBlur = 5;
          c.font = FONT.pingfangR(delFs);

          var txt = "删除"
          var tw = c.measureText(txt).width;
          delWidth = 50 + delFs + tw;
          delWidth = (delWidth > 200 ? delWidth : 200);
          c.roundRect(0, 0, delWidth, delHeight, 5);
          c.fill();
          page.whenClick(0, 0, delWidth, delHeight, function() {
            $(page).trigger({
              type : "removeCart",
              goods : goods
            });
          });
          c.shadowColor = "rgba(0,0,0,1)";
          c.t(delWidth / 2, delHeight / 2);
          c.fillStyle = "white";
          var cw = tw + 10 + delFs;
          c.fillText(txt, cw / 2 - tw, 0);
          var img = imgs["delete"];
          c.drawImage(img, -cw / 2, -delFs / 2, delFs, delFs);

        });

        return self.height;
      });

      /**
       * 购物车列表面板.
       */
      gegewu.CartPanel = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({
          tipPadding : 10,
          tipFontSize : 48,
          tipColor : "white",
          noGoodsTip : "购物车中没有商品"
        }, settings);
        self.settings.tm = $.now();

        self.subPanel = new gegewu.CartSubPanel();
      }, "ggwCartPanel");

      /**
       * 绘制购物车.
       */
      defFunc(gegewu.CartPanel, "renderCart",
          function(page, c, vw, vh, bw, bh) {
            var self = this;
            var cart = page.cart;
            var p = self.subPanel;
            var height = 700;// 一个商品面板的完整高度，包括上下padding
            $(cart.commodities).each(function(i) {
              c.t(0, i * height);
              p.setGoods(this);
              p.setHeight(height);
              c.render(function() {
                p.renderComp(page, c, vw, vh, bw, bh);
              });
            });
            return height * cart.commodities.length;
          });

      defFunc(gegewu.CartPanel, "renderWhenNoGoods",
      /**
       * 购物车中没有商品的时候显示提示信息.
       */
      function(page, c, vw, vh, bw, bh) {
        var self = this;
        var padding = self.settings.tipPadding;
        var padding_dl = padding * 2;
        var txt = self.settings.noGoodsTip;
        var fs = self.settings.tipFontSize;
        c.render(function() {
          c.font = FONT.pingfangR(fs);
          var tw = c.measureText(txt).width;
          var tw_h = tw / 2;
          var fs_h = fs / 2;
          c.t(vw / 2, fs_h + padding);// 移动到提示文字的中心位置.
          c.fillStyle = self.settings.tipColor;
          c.fillText(txt, -tw_h, 0);
        });
        return fs + padding_dl;
      });

      defFunc(gegewu.CartPanel, "renderComp",
          function(page, c, vw, vh, bw, bh) {
            var self = this;
            var cart = page.cart;
            var height = 0;
            if (!cart || cart.count < 1) {
              height = self.renderWhenNoGoods(page, c, vw, vh, bw, bh);
            } else {
              height = self.renderCart(page, c, vw, vh, bw, bh);
            }

            self.settings.height = self.height = height;
          });

      /**
       * 购物车页页脚.
       */
      gegewu.CartFooter = defClass(Footer, function(settings) {
        this.btnChgAdd = new TextButton({
          text : "更换地址",
          fontSize : 50,
          font : FONT.pingfangR,
          color : "white",
          bgColor : "orange",
          padding : 10,
          isCenter : true
        });
        this.btnDate = new TextButton({
          text : "明日配送",
          fontSize : 50,
          font : FONT.pingfangR,
          color : "white",
          bgColor : "darkgreen",
          padding : 10,
          isCenter : true
        });
        this.nextButton = new TextButton({
          text : "确认购买",
          fontSize : 50,
          font : FONT.pingfangR,
          color : "white",
          bgColor : "red",
          padding : 10,
          isCenter : true
        });
      }, "ggwCartFooter");
      // 类说明.
      gegewu.CartFooter.prototype.__desc = "购物车页脚";
      // 下一步按钮.
      gegewu.CartFooter.prototype.nextButton = undefined;

      // 购物车中没有商品时的页脚
      defFunc(gegewu.CartFooter, "renderEmptyCartFooter", function(page, c, vw,
          vh, bw, bh) {

        var fs = this.height / 6;
        c.font = FONT.pingfangR(fs);
        c.fillStyle = this.color;
        c.t(vw / 2, this.height / 2);
        var txt = "购物车中没有物品!";
        var tw = c.measureText(txt).width;
        c.fillText(txt, -tw / 2, 0);
      });

      // 渲染购物车信息部分
      defFunc(gegewu.CartFooter, "renderCartSummaryInfo", function(page, c, vw,
          vh, bw, bh) {
        var self = this;
        if (!page.cartLoadStatus) {
          return;
        }
        c.render(function() {
          var cart = page.cart;
          var count = 0;
          var ccount = cart.commodities.length;
          var total = 0;
          $(cart.commodities).each(function() {
            count += this.amount;
            total += this.amount * this.price;
          });

          var txt = ccount + "种商品,共" + count + "件,合计"
              + $.numberUtils("format", total / 100, "0.99") + "元";
          var tw = 0;
          var fs = 48;
          var fs_h = fs / 2;
          var padding = 10;
          c.font = FONT.pingfangR(fs);
          c.fillStyle = "white";
          tw = c.measureText(txt).width;
          c.t(vw / 2, padding + fs_h);
          c.fillText(txt, -tw / 2, 0);
        });
      });

      // 购物车中的地址.
      defFunc(gegewu.CartFooter, "renderAddress", function(page, c, vw, vh, bw,
          bh) {
        if (!page.addressesLoadStatus) {
          return;
        }
        var self = this;
        var ads = page.addresses;
        var address = "";
        if (ads.length == 0) {
          address = "还没有您的收货地址，请再\"设置\"中添加您的收货地址";
        } else {
          var default_address = null;
          $(ads).each(function(i) {
            if (i == 0) {
              default_address = this;
            }
            if (this.defaultAdd == true) {
              default_address = this;
              return false;
            }
          });
          address = default_address;
        }

        if (typeof address == "string") {
          var fs = 48;
          var fs_h = fs / 2;
          var padding = 10;
          c.render(function() {
            c.t(padding, padding + fs_h);
            PAINTS.footTxt(c, fs);
            // var tw = c.measureText(address);
            c.fillText(address, 0, 0, vw - padding * 2);
          });
        } else {
          self.address = address;
          var postcode = address.postCode;
          var add = address.address;
          var name = address.receiverName;
          var phone = address.phone;
          var fs = 48;
          var fs_h = fs / 2;
          var padding = 10;
          var padding2 = padding * 2;
          var maxwid = vw - padding * 2;
          c.render(function() {
            c.t(padding, padding + fs_h);
            PAINTS.footTxt(c, fs);
            c.fillText("地址:" + add, 0, 0, maxwid);
            c.t(0, fs + padding2);
            c.fillText(name + "(收) 电话:" + phone + " 邮编:" + postcode, 0, 0,
                maxwid);

          });
        }

      });

      // 购物车中有商品时的页脚
      defFunc(gegewu.CartFooter, "renderCartFooter", function(page, c, vw, vh,
          bw, bh) {
        var self = this;
        var args = arguments;
        c.render(function() {
          self.renderCartSummaryInfo.apply(self, args);// 购物车信息部分.
          c.t(0, 68);// padding:10*2,font size:48
          self.renderAddress.apply(self, args);
          c.t(0, 68 * 2);
          var height = self.height - 68 * 3;
          c.t(vw / 3 - 175, height / 2);
          // c.fillStyle = "red";
          // c.fillRect(-10, -10, 20, 20);

          var btn = self.btnChgAdd;
          btn.top = 0;
          btn.left = 0;
          btn.onClick = function() {
            wizard.switch2AddressMng(page);
          };
          btn.render.apply(btn, args)
          
          c.t(vw/3, 0);
          
          var btn = self.btnDate;
          btn.top = 0;
          btn.left = 0;
          var txt = "";
          if(!serv.isBlankStr(page.receiveDate)){
            txt=page.receiveDate+" ";
          }
          if(!serv.isBlankStr(page.receiveTime)){
            txt+=page.receiveTime;
          }
          if(!serv.isBlankStr(txt)){
            btn.text = txt;
          }else{
            btn.text="明日配送";
          }
          //console.log(page.receiveDate+","+page.receiveTime)
          
          btn.onClick = function() {
            var event = {
              type : "chgDate"
            };
            $(page).trigger(event);
          };
          btn.render.apply(btn, args);

          c.t(vw/3, 0);
          
          var btn = self.nextButton;
          btn.top = 0;
          btn.left = 0;
          btn.onClick = function() {
            var event = {
              type : "commitCart",
              address : self.address
            };
            $(page).trigger(event);
          };
          btn.render.apply(btn, args);
        });
      });
      // 渲染购物车页脚
      defFunc(gegewu.CartFooter, "renderComp",
          function(page, c, vw, vh, bw, bh) {
            this["renderComp::Footer"].apply(this, arguments);// 背景色
            if (page.cart.count == 0) {
              this.renderEmptyCartFooter.apply(this, arguments);
            } else {
              this.renderCartFooter.apply(this, arguments);
            }
          });

      /**
       * 横线
       */
      gegewu.Bar = defClass(Component, function(settings) {

      }, "ggwBar");

      gegewu.Bar.prototype.settings.left = 0;
      gegewu.Bar.prototype.settings.top = 0;
      gegewu.Bar.prototype.settings.width = 0;
      gegewu.Bar.prototype.settings.height = 0;
      gegewu.Bar.prototype.settings.lineWidth = 1;
      gegewu.Bar.prototype.settings.color = "white";
      gegewu.Bar.prototype.settings.shadowColor = "rgba(0,0,0,1)";
      gegewu.Bar.prototype.settings.shadowBlur = 0;
      gegewu.Bar.prototype.settings.shadowOffsetX = 0;
      gegewu.Bar.prototype.settings.shadowOffsetY = 0;

      defFunc(gegewu.Bar, "renderComp", function(page, c, vw, vh, bw, bh) {
        ;
        var self = this;
        if ((!self.width) || self.width <= 0) {
          self.width = vw;
        }
        self.height = self.settings.lineWidth;
        // console.log("settings:"+JSON.stringify(self.settings));
        c.render(function() {
          c.t(self.left, self.top);
          c.strokeStyle = self.settings.color;
          c.lineWidth = self.settings.lineWidth;
          c.shadowColor = self.settings.shadowColor;
          c.shadowBlur = self.settings.shadowBlur;
          c.shadowOffsetX = self.settings.shadowOffsetX;
          c.shadowOffsetY = self.settings.shadowOffsetY;
          c.strokeLine(self.width, 0);
        });
      });

      var Title_Space = new EmptyPanel({
        height : 10
      });
      ;
      var Line_Space = new EmptyPanel({
        height : 10
      });
      ;
      
      /**
       * 未发货记录
       * 
       * zhao_f
       */
      
      gegewu.OrderPayTimerPanel=defClass(Panel,function(settings){
    	  var self=this;
    	  
    	  self.titleSpace = Title_Space;
          self.lineSpace = Line_Space;
          
          // 地址内部和操作按钮之间的分割线
          self.innerBar = new gegewu.Bar({
            top : 0,
            left : 50,
            width : 980,
            lineWidth : 2,
            color : "#9c9c9c"
          });

          self.betweenBar = new gegewu.Bar({
            top : 0,
            left : 0,
            width : 1080,
            lineWidth : 10,
            color : "gray"
          });

          self.txtTitle = new TextButton({
            text : "未发货订单列表",
            left : 540,
            top : 24,
            color : "white",
            bgColor : "rgba(255,255,255,0)",
            fontSize : 48,
            font : FONT.pingfangB,
            isCenter : true
          });
      },"ggwOrderPayTimerPanel");

      defFunc(gegewu.OrderPayTimerPanel, "compose",
              function(page, c, vw, vh, bw, bh) {
                var self = this;
                self.clear();
                self.addComp(self.txtTitle);
                self.addComp(self.titleSpace);
                self.addComp(self.betweenBar);
                console.log(JSON.stringify(page.orderHisByTimer));
                $(page.orderHisByTimer).each(
                    function(i) {
                      var his = this;
                      var txt = "";

                      self.addComp(self.lineSpace);
                      txt = $.dateUtils("format", new Date(), "YYYY年MM月DD日");
                      self.addComp(self.lineSpace);
                      self.addComp(new TextButton({
                        text : txt,
                        left : 540,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR,
                        isCenter : true
                      }));

                      var count = 0;
                      $(his.items).each(
                          function(j) {
                        	  
                            txt = this.commodityName
                                + ":"
                                + $.numberUtils("format", this.price / 100, "0.00")
                                + "*"
                                + this.amount
                                + "="
                                + $.numberUtils("format", this.price * this.amount
                                    / 100, "0.00");
                            self.addComp(self.lineSpace);
                            self.addComp(new TextButton({
                              text : txt,
                              left : 100,
                              top : 0,
                              color : "white",
                              bgColor : "rgba(255,255,255,0)",
                              fontSize : 36,
                              font : FONT.pingfangR,
                              isCenter : false
                            }));

                            count += this.amount;
                          });

                      txt = "总金额:"
                          + $.numberUtils("format", his.total / 100, "0.00元,共"
                              + count + "件");
                      self.addComp(self.lineSpace);
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.titleSpace);
                      txt = "地址:" + his.address;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.lineSpace);
                      txt = "邮编:" + his.postCode;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.lineSpace);
                      txt = "电话:" + his.phone;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.lineSpace);
                      txt = "收件人:" + his.receiverName;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));

                      self.addComp(self.lineSpace);
                      
                      //TODO self.addComp(self.innerBar);
                        self.addComp(self.lineSpace); 
                        self.addComp(new TextButton({
                          text : "待发货",
                          left : 270,
                          top : 28,
                          color : "white",
                          bgColor : "red",
                          fontSize : 36,
                          font : FONT.pingfangR,
                          padding : 10,
                          isCenter : true,
                          onClick : function() {
                        	  serv.updatePayTimeOrder(page,his, function() {
                                  var as = [];
                                  var postarr=[];
                                  $(page.orderHisByTimer).each(function() {
                                    if (this != his) {
                                      as[as.length] = this;
                                    }
                                  });
                                  $(page.orderPostByTimer).each(function() {
                                    	  postarr[postarr.length] = this;
                                  });
                                  postarr[postarr.length]=his;
                                  page.orderPostByTimer=postarr;
                                  page.orderHisByTimer = as;
                                });
                          }
                        }));
                        self.addComp(new TextButton({
                          text : "已发货",
                          left : 810,
                          top : -28,
                          height : -1,
                          color : "white",
                          bgColor : "red",
                          fontSize : 36,
                          font : FONT.pingfangR,
                          padding : 10,
                          isCenter : true,
                          onClick : function() {
                        	  serv.updatePayTimeToFinishTimeOrder(page,his, function() {
                                  var as = [];
                                  var finisharr=[];
                                  $(page.orderHisByTimer).each(function() {
                                    if (this != his) {
                                      as[as.length] = this;
                                    }
                                  });
                                  $(page.orderFinishByTimer).each(function() {
                                	  postarr[postarr.length] = this;
                                  });
                                  finisharr[finisharr.length]=his;
                                  page.orderFinishByTimer=finisharr;
                                  page.orderHisByTimer = as;
                                });
                          }
                        }));
                      self.addComp(self.lineSpace);
                      self.addComp(self.betweenBar);
                    });
              });

      // 渲染未发货订单列表
      defFunc(gegewu.OrderPayTimerPanel, "renderComp", function(page, c, vw, vh, bw,
          bh) {
        this.compose(page, vw, vh);
        this["renderComp::Panel"].apply(this, arguments);
        this.height = this.contentHeight;
      });
      //zhao_f  未发货记录  end
      
      //zhao_f 待发货
      gegewu.OrderPostTimerPanel=defClass(Panel,function(settings){
    	  var self=this;
    	  
    	  self.titleSpace = Title_Space;
          self.lineSpace = Line_Space;
          
          // 地址内部和操作按钮之间的分割线
          self.innerBar = new gegewu.Bar({
            top : 0,
            left : 50,
            width : 980,
            lineWidth : 2,
            color : "#9c9c9c"
          });

          self.betweenBar = new gegewu.Bar({
            top : 0,
            left : 0,
            width : 1080,
            lineWidth : 10,
            color : "gray"
          });

          self.txtTitle = new TextButton({
            text : "待发货订单列表",
            left : 540,
            top : 24,
            color : "white",
            bgColor : "rgba(255,255,255,0)",
            fontSize : 48,
            font : FONT.pingfangB,
            isCenter : true
          });
      },"ggwOrderPostTimerPanel");

      defFunc(gegewu.OrderPostTimerPanel, "compose",
              function(page, c, vw, vh, bw, bh) {
                var self = this;
                self.clear();
                self.addComp(self.txtTitle);
                self.addComp(self.titleSpace);
                self.addComp(self.betweenBar);

                $(page.orderPostByTimer).each(
                    function(i) {
                      var his = this;
                      var txt = "";

                      self.addComp(self.lineSpace);
                      txt = $.dateUtils("format", new Date(), "YYYY年MM月DD日");
                      self.addComp(self.lineSpace);
                      self.addComp(new TextButton({
                        text : txt,
                        left : 540,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR,
                        isCenter : true
                      }));

                      var count = 0;
                      $(his.items).each(
                          function(j) {
                        	  
                            txt = this.commodityName
                                + ":"
                                + $.numberUtils("format", this.price / 100, "0.00")
                                + "*"
                                + this.amount
                                + "="
                                + $.numberUtils("format", this.price * this.amount
                                    / 100, "0.00");
                            self.addComp(self.lineSpace);
                            self.addComp(new TextButton({
                              text : txt,
                              left : 100,
                              top : 0,
                              color : "white",
                              bgColor : "rgba(255,255,255,0)",
                              fontSize : 36,
                              font : FONT.pingfangR,
                              isCenter : false
                            }));

                            count += this.amount;
                          });

                      txt = "总金额:"
                          + $.numberUtils("format", his.total / 100, "0.00元,共"
                              + count + "件");
                      self.addComp(self.lineSpace);
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.titleSpace);
                      txt = "地址:" + his.address;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.lineSpace);
                      txt = "邮编:" + his.postCode;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.lineSpace);
                      txt = "电话:" + his.phone;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.lineSpace);
                      txt = "收件人:" + his.receiverName;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));

                      self.addComp(self.lineSpace);
                      
                      //TODO self.addComp(self.innerBar);
                        self.addComp(self.lineSpace); 
                        self.addComp(new TextButton({
                          text : "已发货",
                          left : 810,
                          top : 28,
                          color : "white",
                          bgColor : "red",
                          fontSize : 36,
                          font : FONT.pingfangR,
                          padding : 10,
                          isCenter : true,
                          onClick : function() {
                        	  serv.updateFinishTimeOrder(page,his, function() {
                                  var as = [];
                                  var finisharr=[];
                                  $(page.orderPostByTimer).each(function() {
                                    if (this != his) {
                                      as[as.length] = this;
                                    }
                                  });
                                  $(page.orderFinishByTimer).each(function() {
                                	  postarr[postarr.length] = this;
                                  });
                                  finisharr[finisharr.length]=his;
                                  page.orderFinishByTimer=finisharr;
                                  page.orderPostByTimer = as;
                                  
                                });
                          }
                        }));
                       
                      self.addComp(self.lineSpace);
                      self.addComp(self.betweenBar);
                    });
              });

      // 渲染待发货订单列表
      defFunc(gegewu.OrderPostTimerPanel, "renderComp", function(page, c, vw, vh, bw,
          bh) {
        this.compose(page, vw, vh);
        this["renderComp::Panel"].apply(this, arguments);
        this.height = this.contentHeight;
      });
      //zhao_f 待发货  end
      //zhao_f 已发货
      gegewu.OrderFinishTimerPanel=defClass(Panel,function(settings){
    	  var self=this;
    	  
    	  self.titleSpace = Title_Space;
          self.lineSpace = Line_Space;
          
          // 地址内部和操作按钮之间的分割线
          self.innerBar = new gegewu.Bar({
            top : 0,
            left : 50,
            width : 980,
            lineWidth : 2,
            color : "#9c9c9c"
          });

          self.betweenBar = new gegewu.Bar({
            top : 0,
            left : 0,
            width : 1080,
            lineWidth : 10,
            color : "gray"
          });

          self.txtTitle = new TextButton({
            text : "已发货订单列表",
            left : 540,
            top : 24,
            color : "white",
            bgColor : "rgba(255,255,255,0)",
            fontSize : 48,
            font : FONT.pingfangB,
            isCenter : true
          });
      },"ggwOrderFinishTimerPanel");

      defFunc(gegewu.OrderFinishTimerPanel, "compose",
              function(page, c, vw, vh, bw, bh) {
                var self = this;
                self.clear();
                self.addComp(self.txtTitle);
                self.addComp(self.titleSpace);
                self.addComp(self.betweenBar);

                $(page.orderFinishByTimer).each(
                    function(i) {
                      var his = this;
                      var txt = "";

                      self.addComp(self.lineSpace);
                      txt = $.dateUtils("format", new Date(), "YYYY年MM月DD日");
                      self.addComp(self.lineSpace);
                      self.addComp(new TextButton({
                        text : txt,
                        left : 540,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR,
                        isCenter : true
                      }));

                      var count = 0;
                      $(his.items).each(
                          function(j) {
                        	  
                            txt = this.commodityName
                                + ":"
                                + $.numberUtils("format", this.price / 100, "0.00")
                                + "*"
                                + this.amount
                                + "="
                                + $.numberUtils("format", this.price * this.amount
                                    / 100, "0.00");
                            self.addComp(self.lineSpace);
                            self.addComp(new TextButton({
                              text : txt,
                              left : 100,
                              top : 0,
                              color : "white",
                              bgColor : "rgba(255,255,255,0)",
                              fontSize : 36,
                              font : FONT.pingfangR,
                              isCenter : false
                            }));

                            count += this.amount;
                          });

                      txt = "总金额:"
                          + $.numberUtils("format", his.total / 100, "0.00元,共"
                              + count + "件");
                      self.addComp(self.lineSpace);
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.titleSpace);
                      txt = "地址:" + his.address;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.lineSpace);
                      txt = "邮编:" + his.postCode;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.lineSpace);
                      txt = "电话:" + his.phone;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));
                      self.addComp(self.lineSpace);
                      txt = "收件人:" + his.receiverName;
                      self.addComp(new TextButton({
                        text : txt,
                        left : 100,
                        top : 0,
                        color : "white",
                        bgColor : "rgba(255,255,255,0)",
                        fontSize : 36,
                        font : FONT.pingfangR
                      }));

                      self.addComp(self.lineSpace);
                      
                      //TODO self.addComp(self.innerBar);
                      //self.addComp(self.lineSpace); 
                      self.addComp(self.lineSpace);
                      self.addComp(self.betweenBar);
                    });
              });

      // 渲染待发货订单列表
      defFunc(gegewu.OrderFinishTimerPanel, "renderComp", function(page, c, vw, vh, bw,
          bh) {
        this.compose(page, vw, vh);
        this["renderComp::Panel"].apply(this, arguments);
        this.height = this.contentHeight;
      });
      //zhao_f 已发货 end
      //zhao_f  操作提示
      /**
       * 提示
       */
      gegewu.OperationShadeTip = defClass(Component, function(settings) {
        var self = this;
        self.settings = $.extend({
          backgroundColor : "white",
          backgroundAlpha : "0.7",
          image : "loading",
          text : "正在操作，请稍后",
          isAppendDot : true,
          maxDotCount : 3,
          dot : ".",
          textColor : "white",
          textShadowColor : "black",
          fontSize : 48,
          shadowBlur : 5,
          shadowOffsetX : 3,
          shadowOffsetY : 5,
          direct : 0, // 0-clockwise;1-counter clockwise
          onClick : $.noop
        }, settings);
        self.settings.tm = $.now();

      }, "ggwOperationShadeTip");

      defFunction(gegewu.OperationShadeTip, "renderComp", function(page, c, vw, vh, bw,
          bh) {
        var self = this;
        var tm = $.now();
        var dd = tm - self.settings.tm;
        var a = dd % 10000 * Math.PI * 2 / 10000;
        c.render(function() {
          c.fillStyle = self.settings.backgroundColor;
          c.globalAlpha = self.settings.backgroundAlpha;
          c.fillRect(0, 0, vw, vh);
          page.whenClick(0, 0, vw, vh, function() {
            var fn = self.settings.onClick;
            var res = undefined;
            if (fn && $.isFunction(fn)) {
              res = self.settings.onClick();
            }
            return res;
          });
        });
        var w = 0;
        var h = 0;
        c.render(function() {
          var img = window.imgs[self.settings.image];
          if (img && img.loaded) {
            w = img.width;
            h = img.height;
            c.t(vw / 2, vh / 2);
            c.rotate((self.settings.direct == 0 ? 1 : -1) * a);
            c.drawImage(img, -w / 2, -h / 2);
          }
        });

        var txt = self.settings.text;
        if (self.settings.isAppendDot) {
          var dot_count = Math.floor(dd / 1000) % self.settings.maxDotCount;
          for (var i = 0; i <= dot_count; i++) {
            txt += self.settings.dot;
          }
        }
        c.font = FONT.pingfangR(self.settings.fontSize);
        c.fillStyle = self.settings.textColor;
        c.shadowColor = self.settings.textShadowColor;
        c.shadowBlur = self.settings.shadowBlur;
        c.shadowOffsetX = self.settings.shadowOffsetX;
        c.shadowOffsetY = self.settings.shadowOffsetY;
        c.t(vw / 2, vh / 2 + -h / 2 - self.settings.fontSize);
        var tw = c.measureText(txt).width;
        c.fillText(txt, -tw / 2, self.settings.fontSize / 2);

      });
      //zhao_f 操作提示 end
      /**
       * 订单历史记录
       */

      gegewu.OrderHisPanel = defClass(Panel, function(settings) {
        var self = this;

        self.titleSpace = Title_Space;
        self.lineSpace = Line_Space;

        // 地址内部和操作按钮之间的分割线
        self.innerBar = new gegewu.Bar({
          top : 0,
          left : 50,
          width : 980,
          lineWidth : 2,
          color : "#9c9c9c"
        });

        self.betweenBar = new gegewu.Bar({
          top : 0,
          left : 0,
          width : 1080,
          lineWidth : 10,
          color : "gray"
        });

        self.txtTitle = new TextButton({
          text : "订单列表",
          left : 540,
          top : 24,
          color : "white",
          bgColor : "rgba(255,255,255,0)",
          fontSize : 48,
          font : FONT.pingfangB,
          isCenter : true
        });

      }, "ggwOrderHisPanel");

      defFunc(gegewu.OrderHisPanel, "compose",
          function(page, c, vw, vh, bw, bh) {
            var self = this;
            self.clear();
            self.addComp(self.txtTitle);
            self.addComp(self.titleSpace);
            self.addComp(self.betweenBar);

            $(page.orderHis).each(
                function(i) {
                  var his = this;
                  var txt = "";

                  self.addComp(self.lineSpace);
                  txt = $.dateUtils("format", new Date(), "YYYY年MM月DD日");
                  self.addComp(self.lineSpace);
                  self.addComp(new TextButton({
                    text : txt,
                    left : 540,
                    top : 0,
                    color : "white",
                    bgColor : "rgba(255,255,255,0)",
                    fontSize : 36,
                    font : FONT.pingfangR,
                    isCenter : true
                  }));

                  var count = 0;
                  $(his.items).each(
                      function(j) {

                        txt = this.commodityName
                            + ":"
                            + $.numberUtils("format", this.price / 100, "0.00")
                            + "*"
                            + this.amount
                            + "="
                            + $.numberUtils("format", this.price * this.amount
                                / 100, "0.00");
                        self.addComp(self.lineSpace);
                        self.addComp(new TextButton({
                          text : txt,
                          left : 100,
                          top : 0,
                          color : "white",
                          bgColor : "rgba(255,255,255,0)",
                          fontSize : 36,
                          font : FONT.pingfangR,
                          isCenter : false
                        }));

                        count += this.amount;
                      });

                  txt = "总金额:"
                      + $.numberUtils("format", his.total / 100, "0.00元,共"
                          + count + "件");
                  self.addComp(self.lineSpace);
                  self.addComp(new TextButton({
                    text : txt,
                    left : 100,
                    top : 0,
                    color : "white",
                    bgColor : "rgba(255,255,255,0)",
                    fontSize : 36,
                    font : FONT.pingfangR
                  }));
                  self.addComp(self.titleSpace);
                  txt = "地址:" + his.address;
                  self.addComp(new TextButton({
                    text : txt,
                    left : 100,
                    top : 0,
                    color : "white",
                    bgColor : "rgba(255,255,255,0)",
                    fontSize : 36,
                    font : FONT.pingfangR
                  }));
                  self.addComp(self.lineSpace);
                  txt = "邮编:" + his.postCode;
                  self.addComp(new TextButton({
                    text : txt,
                    left : 100,
                    top : 0,
                    color : "white",
                    bgColor : "rgba(255,255,255,0)",
                    fontSize : 36,
                    font : FONT.pingfangR
                  }));
                  self.addComp(self.lineSpace);
                  txt = "电话:" + his.phone;
                  self.addComp(new TextButton({
                    text : txt,
                    left : 100,
                    top : 0,
                    color : "white",
                    bgColor : "rgba(255,255,255,0)",
                    fontSize : 36,
                    font : FONT.pingfangR
                  }));
                  self.addComp(self.lineSpace);
                  txt = "收件人:" + his.receiverName;
                  self.addComp(new TextButton({
                    text : txt,
                    left : 100,
                    top : 0,
                    color : "white",
                    bgColor : "rgba(255,255,255,0)",
                    fontSize : 36,
                    font : FONT.pingfangR
                  }));

                  self.addComp(self.lineSpace);
                  /*
                   * //TODO self.addComp(self.innerBar);
                   * self.addComp(self.lineSpace); self.addComp(new TextButton({
                   * text:"查看订单", left:540,top:23, color:"white",bgColor:"red",
                   * fontSize:36,font:FONT.pingfangR, padding:10, isCenter:true
                   * }));
                   */
                  self.addComp(self.lineSpace);
                  self.addComp(self.betweenBar);
                });
          });

      // 渲染订单历史记录
      defFunc(gegewu.OrderHisPanel, "renderComp", function(page, c, vw, vh, bw,
          bh) {
        this.compose(page, vw, vh);
        this["renderComp::Panel"].apply(this, arguments);
        this.height = this.contentHeight;
      });

      /**
       * 我（或者叫设置）页面中地址操作部分.
       */
      gegewu.AddressPanel = defClass(Panel, function(settings) {
        var self = this;
        self.titleSpace = Title_Space;
        self.lineSpace = Line_Space;
        self.txtTitle = new TextButton({
          text : "地址管理",
          left : 540,
          top : 24,
          color : "white",
          bgColor : "rgba(255,255,255,0)",
          fontSize : 48,
          font : FONT.pingfangB,
          isCenter : true
        });

        self.txtWaitingForLoading = new TextButton({
          text : "地址加载中，请等待......",
          left : 540,
          top : 0,
          color : "white",
          bgColor : "rgba(255,255,255,0)",
          fontSize : 48,
          font : FONT.pingfangB,
          isCenter : true
        });

        // 地址内部和操作按钮之间的分割线
        self.innerBar = new gegewu.Bar({
          top : 0,
          left : 50,
          width : 980,
          lineWidth : 2,
          color : "#9c9c9c"
        });

        self.betweenBar = new gegewu.Bar({
          top : 0,
          left : 0,
          width : 1080,
          lineWidth : 10,
          color : "gray"
        });

        self.__preAddresses = {};
      }, "ggwAddressPanel");

      // 组装地址显示panel
      gegewu.AddressPanel.prototype.compose = function(page, vw, vh, bw, bh) {

        var self = this;

        var addresses = page.addresses;
        // 在地址没有加载完毕的时候显示提示.
        if (page.addressesLoadStatus != true) {
          self.clear();
          self.addComp(self.txtWaitingForLoading);
          return;
        }

        // 上一次更新的地址和现在地址一样的时候
        // 不重新组装
        if (self.__preAddresses == addresses) {
          return;
        }

        self.clear();
        self.addComp(self.txtTitle);
        self.addComp(self.titleSpace);
        $(addresses).each(
            function(i) {
              var address = this;
              // self.addComp(self.lineSpace);
              var txt = "地址:" + address.address;
              self.addComp(new TextButton({
                text : txt,
                left : 100,
                top : 0,
                color : "white",
                bgColor : "rgba(255,255,255,0)",
                fontSize : 36,
                font : FONT.pingfangR
              }));
              self.addComp(self.lineSpace);
              txt = "邮编:" + address.postCode;
              self.addComp(new TextButton({
                text : txt,
                left : 100,
                top : 0,
                color : "white",
                bgColor : "rgba(255,255,255,0)",
                fontSize : 36,
                font : FONT.pingfangR
              }));
              self.addComp(self.lineSpace);
              txt = "收件人:" + address.receiverName;
              self.addComp(new TextButton({
                text : txt,
                left : 100,
                top : 0,
                color : "white",
                bgColor : "rgba(255,255,255,0)",
                fontSize : 36,
                font : FONT.pingfangR
              }));
              self.addComp(self.lineSpace);
              txt = "电话:" + address.phone;
              self.addComp(new TextButton({
                text : txt,
                left : 100,
                top : 0,
                color : "white",
                bgColor : "rgba(255,255,255,0)",
                fontSize : 36,
                font : FONT.pingfangR
              }));
              self.addComp(self.lineSpace);
              self.addComp(self.innerBar);
              self.addComp(self.titleSpace);
              if (address.defaultAdd) {
                var txt = "默认地址";
                self.addComp(new TextButton({
                  text : txt,
                  left : 540,
                  top : 28,
                  color : "white",
                  bgColor : "#5e5e5e",
                  fontSize : 36,
                  font : FONT.pingfangR,
                  padding : 10,
                  isCenter : true
                }));
              } else {
                var txt = "设为默认";
                self.addComp(new TextButton({
                  text : txt,
                  left : 270,
                  top : 28,
                  color : "white",
                  bgColor : "red",
                  fontSize : 36,
                  font : FONT.pingfangR,
                  padding : 10,
                  isCenter : true,
                  onClick : function() {
                    $(addresses).each(function() {
                      this.defaultAdd = false;
                    });
                    address.defaultAdd = true;

                    serv.updateAsDefaultAddress
                        && serv.updateAsDefaultAddress(address);

                    // console.log(JSON.stringify(address));
                    self.__preAddresses = {};
                  }
                }));
                txt = "不再使用";
                self.addComp(new TextButton({
                  text : txt,
                  left : 810,
                  top : -28,
                  height : -1,
                  color : "white",
                  bgColor : "red",
                  fontSize : 36,
                  font : FONT.pingfangR,
                  padding : 10,
                  isCenter : true,
                  onClick : function() {

                    serv.unuseAddress(address, function() {
                      var as = [];
                      $(page.addresses).each(function() {
                        if (this != address) {
                          as[as.length] = this;
                        }
                      });
                      page.addresses = as;
                    });
                  }
                }));

              }
              self.addComp(self.titleSpace);
              self.addComp(self.titleSpace);
              if (addresses && i < addresses.length - 1) {
                self.addComp(self.betweenBar);
                self.addComp(self.titleSpace);
              }

            });

        self.__preAddresses = addresses;
      }

      /**
       * 个人设置.
       */
      //{{{
      gegewu.SettingsPanel = defClass(Panel, function(settings) {
	      var self = this;
	      var txt = "修改个人信息";
	      self.btnModify=new TextButton({
			  text : txt,
			  left : 540,
			  top : 50,
			  fontSize : 36,
			  font : FONT.pingfangR,
			  color : "white",
			  bgColor : "red",
			  isCenter : true,
			  radius:5,
			  padding : 10
		  });

	      txt = "管理收货地址";
	      self.btnMngAdd=new TextButton({
			  text : txt,
			  left : 540,
			  top : 50,
			  fontSize : 36,
			  font : FONT.pingfangR,
			  color : "white",
			  bgColor : "red",
			  isCenter : true,
			  radius:5,
			  padding : 10
		  });


	      txt = "个人信息";
	      self.txtTitle=new TextButton({
		      text : txt,
		      left : 540,
		      top : 30,
		      fontSize : 48,
		      font : FONT.pingfangR,
		      color : "white",
		      bgColor : "rgba(255,255,255,0)",
		      isCenter : true,
		      padding : 5
		  });
	      txt = "收货地址";
	      self.txtAddTitle=new TextButton({
		      text : txt,
		      left : 540,
		      top : 30,
		      fontSize : 48,
		      font : FONT.pingfangR,
		      color : "white",
		      bgColor : "rgba(255,255,255,0)",
		      isCenter : true,
		      padding : 5
		      
		  });
	      
	      self.betweenBar = new gegewu.Bar({
		      top : 0,
		      left : 0,
		      width : 1080,
		      lineWidth : 10,
		      color : "gray"
		  });
	      self.titleSpace = Title_Space;
	      self.lineSpace = Line_Space;

	      
      }, "ggwSettingsPanel");

      gegewu.SettingsPanel.prototype.__onModifySelfInfo=function(page,c,vw,vh,bw,bh){

        var self = this;
        var $html = $("<div style='position:absolute;top:0px;left:0px;width:100%;height:100%;background-color:rgba(255,255,255,0.85);z-index:0;'>&nbsp;</div>");
        $("body").css("z-index", 0);
        var $title = $("<div style='color:black;width:100%;text-align:center;font-size:36px;z-index:0;'>修改个人信息</div>");
        var $txtNickName = $("<div style='color:black;' align='center'><input id='txtNickName' placeholder='请输入您的昵称' style='z-index:1;width:80%;height:1.5em;font-size:24px;margin:5px;'></div>");
        var $txtPhone = $("<div style='color:black;' align='center'><input id='txtPhone' placeholder='请输入您的电话' style='z-index:1;width:80%;height:1.5em;font-size:24px;margin:5px;'></div>");
        var $bg = $("<div style='position:absolute;top:40px;left:5%;width:90%;height:8em;background-color:orange;z-index:0;'>&nbsp;</div>");
        var $txtOk = $('<a id="btnok" href="#" class="weui_btn_dialog primary" style="font-size:24px;">确定</a>');
        var $txtCancel = $('<a id="btnok" href="#" class="weui_btn_dialog default" style="font-size:24px;">取消</a>');
        $html.append($title);
        $bg.append($txtNickName);
        $bg.append($txtPhone);
        $html.append($bg);

        $("body").append($html);
        $bg.offset({
          top : $title.offset().top + $title.height() + 5
        });
        $bg.height($txtPhone.offset().top - $bg.offset().top
            + $txtPhone.outerHeight() + 50);

        $html.append($txtOk);
        $html.append($txtCancel);

        var s = ($html.width() - $txtOk.width() - $txtCancel.width()) / 3;

        $txtOk.offset({
          top : $bg.offset().top + $bg.height() - 35,
          left : s * 2 + $txtOk.width()
        });
        $txtCancel.offset({
          top : $bg.offset().top + $bg.height() - 35,
          left : s
        });

        $txtCancel.on("click", function() {
          $html.detach();
        });
        $txtOk.on("click", function() {
          var nickname = $html.find("#txtNickName").val();
          var phone = $html.find("#txtPhone").val();

          var msg = ""
          if ("" == nickname.trim()) {
            msg += ("昵称不能为空！\n");
          }
          if ("" == phone.trim()) {
            msg += ("电话不能为空！\n");
          }
          if (!/[1]\d{10}(?!\d)/.test(phone)) {
            msg += ("电话应该是11位数字！");
          }

          if (msg != "") {
            alert(msg)
            $("div").detach();
            return;
          }

          var param = {
            nickname : nickname,
            phone : phone
          };
          $(page).trigger({type:"updateUserBaseInfo","baseInfo":param})
        });
      
      }
      defFunc(gegewu.SettingsPanel, "onModifySelfInfo",
	      gegewu.SettingsPanel.prototype.__onModifySelfInfo);

      gegewu.SettingsPanel.prototype.__compose=function(page,c,vw,vh,bw,bh){
	  var self = this;
	  var txt = "";
	  //console.log(page+","+page.cart+","+page.cart.user);
	  if(page&&page.cart&&page.cart.user){
	      var user = page.cart.user;
	      if(self.__preuser!=user){
		  
		  self.clear();
		  self.__preuser=user;
		  
		  self.addComp(self.txtTitle);
		  
		  txt = "昵称:"+(user.nickname?user.nickname:"未设置");
		  self.addComp(new TextButton({
			      text : txt,
				  left : 50,
				  top : 24,
				  fontSize : 36,
				  font : FONT.pingfangR,
				  color : "white",
				  bgColor : "rgba(255,255,255,0)",
				  isCenter : false,
				  padding : 5
				  }));
		  txt = "手机:"+(user.phone?user.phone:"未设置");
		  self.addComp(new TextButton({
			      text : txt,
				  left : 50,
				  top : 24,
				  fontSize : 36,
				  font : FONT.pingfangR,
				  color : "white",
				  bgColor : "rgba(255,255,255,0)",
				  isCenter : false,
				  padding : 5
				  }));
		  txt = "身份:"+(user.status==1?"VIP客户":"普通客户");
		  self.addComp(new TextButton({
			      text : txt,
				  left : 50,
				  top : 24,
				  fontSize : 36,
				  font : FONT.pingfangR,
				  color : "white",
				  bgColor : "rgba(255,255,255,0)",
				  isCenter : false,
				  padding : 5
				  }));
		  
		  txt = "积分:"+(user.score?user.score:0)+"分";
		  self.addComp(new TextButton({
			      text : txt,
				  left : 50,
				  top : 24,
				  fontSize : 36,
				  font : FONT.pingfangR,
				  color : "white",
				  bgColor : "rgba(255,255,255,0)",
				  isCenter : false,
				  padding : 5
				  }));

		  self.btnModify.onClick=function(){
		      self.onModifySelfInfo(page,c,vw,vh,bw,bh);
		  }

		  self.addComp(self.btnModify);
		  self.addComp(self.lineSpace);
		  self.addComp(self.lineSpace);
		  self.addComp(self.lineSpace);
		  self.addComp(self.lineSpace);
		  self.addComp(self.betweenBar);
		  self.addComp(self.lineSpace);
		  var addresses = page.addresses;
		  var address = addresses?(function(s){
			  var res = null;
			  $(s).each(function(){
				  if(this.defaultAdd==true){
				      res = this;
				      return false;
				  }
			      });
			  return res;
		      })(addresses):null;

		  self.addComp(self.txtAddTitle);
		  self.addComp(self.titleSpace);
		  
		  if(address){
		      txt = "送货地址:"+address.address;
		      self.addComp(new TextButton({
				  text : txt,
				      left : 50,
				      top : 24,
				      fontSize : 36,
				      font : FONT.pingfangR,
				      color : "white",
				      bgColor : "rgba(255,255,255,0)",
				      isCenter : false,
				      padding : 5
				      }));
		      txt = "邮政编码:"+address.postCode;
		      self.addComp(new TextButton({
				  text : txt,
				      left : 50,
				      top : 24,
				      fontSize : 36,
				      font : FONT.pingfangR,
				      color : "white",
				      bgColor : "rgba(255,255,255,0)",
				      isCenter : false,
				      padding : 5
				      }));
		      txt = "收件人:"+address.receiverName;
		      self.addComp(new TextButton({
				  text : txt,
				      left : 50,
				      top : 24,
				      fontSize : 36,
				      font : FONT.pingfangR,
				      color : "white",
				      bgColor : "rgba(255,255,255,0)",
				      isCenter : false,
				      padding : 5
				      }));
		      txt = "电话:"+address.phone;
		      self.addComp(new TextButton({
				  text : txt,
				      left : 50,
				      top : 24,
				      fontSize : 36,
				      font : FONT.pingfangR,
				      color : "white",
				      bgColor : "rgba(255,255,255,0)",
				      isCenter : false,
				      padding : 5
				      }));
		  }else{
		      txt = "您还没有添加收货地址，请到收货地址管理中添加。";
		      self.addComp(new TextButton({
				  text : txt,
				      left : 50,
				      top : 24,
				      fontSize : 36,
				      font : FONT.pingfangR,
				      color : "white",
				      bgColor : "rgba(255,255,255,0)",
				      isCenter : false,
				      padding : 5
				      }));
		      
		  }
		  
		  self.addComp(self.titleSpace);
		  
		  self.btnMngAdd.onClick=function(){
		      wizard.switch2AddressMng(page);
		  }
		  
		  self.addComp(self.btnMngAdd);
		  
	      }
	  }else{
	      self.clear();
	      self.addComp(new TextButton({
			  text : "获取身份信息中，请等待",
			  left : 540,
			  top : 30,
			  fontSize : 48,
			  font : FONT.pingfangR,
			  color : "white",
			  bgColor : "rgba(255,255,255,0)",
			  isCenter : true,
			  padding : 5	
			
		      }));
	  
      }
	  //console.log(page.cart.user);
      };
    defFunc(gegewu.SettingsPanel, "compose", gegewu.SettingsPanel.prototype.__compose);

      gegewu.SettingsPanel.prototype.__renderComp = function(page, c, vw, vh,
          bw, bh) {
	  this.compose(page,c, vw, vh);

        this["renderComp::Panel"].apply(this, arguments);
        this.height = this.contentHeight;
      };
      defFunc(gegewu.SettingsPanel, "renderComp",
          gegewu.SettingsPanel.prototype.__renderComp);
      //}}}

      /**
       * 我的地址信息页面中的页脚.
       */
      gegewu.AddressFooter = defClass(Footer, function(settings) {
        var self = this;
        self.onAddAddress = settings.onAddAddress;
        self.btnAddAddress = new TextButton({
          text : "添加新地址",
          left : 540,
          top : 55,
          fontSize : 50,
          font : FONT.pingfangR,
          color : "white",
          bgColor : "red",
          padding : 10,
          isCenter : true,
          onClick : function() {
            console.log("gegewu.AddressFooter::onClick()");
            var new_address = self.askNewAddress();
            // serv.newAddress&&(function(add){serv.newAddress(add);})(new_address);
          }
        });
      }, "ggwAddressFooter");

      gegewu.AddressFooter.prototype.askNewAddress = function() {
        var self = this;
        var $html = $("<div style='position:absolute;top:0px;left:0px;width:100%;height:100%;background-color:rgba(255,255,255,0.85);z-index:0;'>&nbsp;</div>");
        $("body").css("z-index", 0);
        var $title = $("<div style='color:black;width:100%;text-align:center;font-size:36px;z-index:0;'>新增地址</div>");
        var $txtAdd = $("<div style='color:black;' align='center'><input id='txtAdd' placeholder='请输入送货地址' style='z-index:1;width:80%;height:1.5em;font-size:24px;margin:5px;'></div>");
        var $txtCon = $("<div style='color:black;' align='center'><input id='txtCon' placeholder='请输入收件人' style='z-index:1;width:80%;height:1.5em;font-size:24px;margin:5px;'></div>");
        var $txtTel = $("<div style='color:black;' align='center'><input id='txtTel' placeholder='请输入收件人电话' style='z-index:1;width:80%;height:1.5em;font-size:24px;margin:5px;'></div>");
        var $txtPos = $("<div style='color:black;' align='center'><input id='txtPos' placeholder='请输入收件地址邮编' style='z-index:1;width:80%;height:1.5em;font-size:24px;margin:5px;'></div>");
        var $bg = $("<div style='position:absolute;top:40px;left:5%;width:90%;height:8em;background-color:orange;z-index:0;'>&nbsp;</div>");
        var $txtOk = $('<a id="btnok" href="#" class="weui_btn_dialog primary" style="font-size:24px;">确定</a>');
        var $txtCancel = $('<a id="btnok" href="#" class="weui_btn_dialog default" style="font-size:24px;">取消</a>');
        $html.append($title);
        $bg.append($txtAdd);
        $bg.append($txtCon);
        $bg.append($txtTel);
        $bg.append($txtPos);
        $html.append($bg);

        $("body").append($html);
        $bg.offset({
          top : $title.offset().top + $title.height() + 5
        });
        $bg.height($txtPos.offset().top - $bg.offset().top
            + $txtPos.outerHeight() + 50);

        $html.append($txtOk);
        $html.append($txtCancel);

        var s = ($html.width() - $txtOk.width() - $txtCancel.width()) / 3;

        $txtOk.offset({
          top : $bg.offset().top + $bg.height() - 35,
          left : s * 2 + $txtOk.width()
        });
        $txtCancel.offset({
          top : $bg.offset().top + $bg.height() - 35,
          left : s
        });

        $txtCancel.on("click", function() {
          $html.detach();
        });
        $txtOk.on("click", function() {
          var add = $html.find("#txtAdd").val();
          var con = $html.find("#txtCon").val();
          var tel = $html.find("#txtTel").val();
          var pos = $html.find("#txtPos").val();

          var msg = ""
          if ("" == add.trim()) {
            msg += ("地址不能为空！\n");
          }
          if ("" == con.trim()) {
            msg += ("需要填写联系人！\n");
          }
          if ("" == tel.trim()) {
            msg += ("需要填写联系电话！\n");
          }

          if ("" == pos.trim()) {
            msg += ("邮编不能为空！");
          }

          if (!/[1-9]\d{5}(?!\d)/.test(pos)) {
            msg += ("邮编应该是6位数字！");
          }

          if (msg != "") {
            alert(msg)
            return;
          }

          var param = {
            add : add,
            con : con,
            tel : tel,
            pos : pos
          };
          // console.log("new
          // Address:"+JSON.stringify(param)+","+self.onAddAddress);
          self.onAddAddress && (function(param) {
            self.onAddAddress(param);
          })(param);
        });

      }

      // 渲染地址页脚
      defFunc(gegewu.AddressFooter, "renderComp", function(page, c, vw, vh, bw,
          bh) {
        this["renderComp::Footer"].apply(this, arguments);// 背景色
        this.btnAddAddress.render.apply(this.btnAddAddress, arguments);
      });

      // 渲染地址
      defFunc(gegewu.AddressPanel, "renderComp", function(page, c, vw, vh, bw,
          bh) {
        this.compose(page, vw, vh);
        this["renderComp::Panel"].apply(this, arguments);
        this.height = this.contentHeight;
      });

      /**
       * 订单信息
       */
      gegewu.OrderPanel = defClass(Panel, function(settings) {
        var self = this;

        self.setOrder(settings ? settings.order : undefined);
        self.onClick = settings.onClick ? settings.onClick : $.noop;

        self.boundaryBar = new gegewu.Bar({
          lineWidth : 2,
          color : "#c4c4c4"
        });
        self.summaryBar = new gegewu.Bar({
          top : 0,
          left : 50,
          width : 980,
          lineWidth : 2,
          color : "#9c9c9c"
        });

        self.titleSpace = Title_Space;// new EmptyPanel({height:50});
        self.lineSpace = Line_Space;// new EmptyPanel({height:10});

        self.txtTitle = new TextButton({
          text : "订单信息",
          left : 540,
          top : 24,
          color : "white",
          bgColor : "rgba(255,255,255,0)",
          fontSize : 48,
          font : FONT.pingfangB,
          isCenter : true
        });
        self.btnCommit = new TextButton({
          text : "支付",
          left : 540,
          top : 48,
          color : "white",
          bgColor : "red",
          fontSize : 48,
          font : FONT.pingfangB,
          isCenter : true,
          padding : 5,
          onClick : function() {

            if (self.order) {
              self.order = null;
              self.text = "等待"
              var fn = self.onClick ? self.onClick : $.noop;
              fn();
            }

          }
        });
        // self.paintTitle=PAINTS.pntOrderTitle;

      }, "ggwOrderPanel");

      /**
       * 设置要显示的订单.
       */
      gegewu.OrderPanel.prototype.setOrder = function(order) {
        if (!order) {
          return;
        }
        if (order != this.settings.order) {
          this.settings.order = order;
        }
        this.__preOrder = (this.order ? this.order : {});
        this.order = order;
      }

      gegewu.OrderPanel.prototype.compose = function(order, vw, vh) {
        if (!this.__preOrder) {
          return;
        }
        var self = this;
        this.clear();
        this.addComp(this.boundaryBar);
        this.addComp(this.titleSpace);
        this.addComp(this.txtTitle);
        this.addComp(this.titleSpace);
        // console.log("order:"+JSON.stringify(this.order));

        $(order.items).each(
            function(i) {
              var goods = this;
              self.addComp(self.lineSpace);

              var txt = (i == 0 ? "  " : "+")
                  + goods.commodityName
                  + " "
                  + $.numberUtils("format", goods.price / 100, "0.00")
                  + "(单价:元)×"
                  + goods.amount
                  + "(个)="
                  + $.numberUtils("format", goods.price * goods.amount / 100,
                      "0.00(元)");
              self.addComp(new TextButton({
                text : txt,
                left : 100,
                top : 0,
                color : "white",
                bgColor : "rgba(255,255,255,0)",
                fontSize : 36,
                font : FONT.pingfangR
              }));
              self.addComp(self.lineSpace);
            });

        this.addComp(this.summaryBar);
        var txt = "合计:" + $.numberUtils("format", order.total / 100, "0.00(元)");
        this.addComp(new TextButton({
          text : txt,
          left : 540,
          top : 0,
          color : "white",
          bgColor : "rgba(255,255,255,0)",
          fontSize : 36,
          font : FONT.pingfangR
        }));
        this.addComp(this.titleSpace);
        this.addComp(this.boundaryBar);
        this.addComp(this.btnCommit);
        // this.addComp(this.endBar);
        this.preOrder = undefined;
      }
      // 渲染订单
      defFunc(gegewu.OrderPanel, "renderComp",
          function(page, c, vw, vh, bw, bh) {
            this.compose(this.order, vw, vh);

            this["renderComp::Panel"].apply(this, arguments);
            this.height = this.contentHeight;
          });

      /**
       * 明细页面页头.
       */
      gegewu.DetailPageHeader = defClass(GroupComponent, function(settings) {
        var self = this;
        this.compBg=new EmptyPanel({height:170,bgColor:"#bc9e79"});
        this.btnBack=new ImageButton({
          image : "iconBack",
          top : 40,
          left : 40,
          width : 90,
          height : 90,
          onClick:function(){$("body").trigger("switchPg00");}
          });
        this.btnHome=new ImageButton({
          image : "iconHome",
          top : 40,
          left : 950,//1080-90-40,
          width : 90,
          height : 90,
          onClick:function(){$("body").trigger("switchPg00");}
          });
        this.txtAzCat=new ImageButton({
          image : "txtAzCat",
          top : (170-114)/2,
          left : (1080-478)/2,//1080-90-40,
          width : 478,
          height : 114,
          });
      }, "ggwDetailPageHeader");
      
      
      gegewu.DetailPageHeader.prototype.compose = function(order, vw, vh) {
        var self = this;
        this.clear();
        this.addComp(this.compBg);
        this.addComp(this.btnBack);
        this.addComp(this.btnHome);
        this.addComp(this.txtAzCat);
      }
      
      defFunc(gegewu.DetailPageHeader, "renderComp",
          function(page, c, vw, vh, bw, bh) {
            this.compose(this.order, vw, vh);
            this["renderComp::GroupComponent"].apply(this, arguments);
            this.height = 170;
          });
      
      
      // --------------------请在此处以上定义类---------------
      return gegewu;
    });